package com.appleyk.service.imp;


import com.appleyk.node.Tuser;
import com.appleyk.relation.Recomm;
import com.appleyk.repository.RecommRepository;
import com.appleyk.repository.TuserRepository;
import com.appleyk.service.RecommService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RecommServiceImp implements  RecommService {

    @Autowired
    private TuserRepository TuserRepository;
    @Autowired
    private RecommRepository RecommRepository;

    @Transactional
    public String  setCreateLikes(Long startNodeID,String name,Long uid,String sex,Integer age,List<String> hobbies) {

        /**
         * 创建节点
         */
        Tuser tuser=new Tuser();
        tuser.setName(name);
        tuser.setUid(uid);
        tuser.setSex(sex);
        tuser.setHobbies(hobbies);
        tuser.setAge(age);

        Tuser nedeTuser=TuserRepository.save(tuser);
        System.out.println("节点创建成功:"+nedeTuser.toString());
        /**
         * 建立关系
         */
         Tuser recomms=RecommRepository.createLikes(startNodeID,uid);


        System.out.println(recomms.toString());

        if(recomms==null){
            return "失败";

        }

            return "成功";

    }

    /**
     * 更具当前用户Uid
     * 查询5-7级内的 推荐
     * @return
     */
    public       List<Recomm> getRecomms(Long uid) {


        System.out.println("进入了业务层");
        List<Recomm> recomms=RecommRepository.getRecomms(uid);

        System.out.println(recomms.toString());


        return recomms;
    }




}
